﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Common;

namespace Agresso.Interface.Layer.Domain
{
    public class DataConversion
    {
        public static Int32 ConvertToInt32(DbDataReader dr, string col)
        {
            return dr[col] is DBNull ? 0 : Convert.ToInt32(dr[col]);
        }
        public static decimal ConvertToDecimal(DbDataReader dr, string col)
        {
            return dr[col] is DBNull ? 0 : Convert.ToDecimal(dr[col]);
        }
        public static DateTime ConvertToDateTime(DbDataReader dr, string col)
        {
            return dr[col] is DBNull ? new DateTime(2000,1,1) : Convert.ToDateTime(dr[col]);
        }
        public static String ConvertToString(DbDataReader dr, string col)
        {
            return dr[col] is DBNull ? "" : Convert.ToString(dr[col]);
        }
        public static bool ConvertToBoolean(DbDataReader dr, string col)
        {
            return dr[col] is DBNull ? false : Convert.ToBoolean(dr[col]);
        }
        public static int ConvertToEnum(DbDataReader dr, string col, Type enumType)
        {
            return dr[col] is DBNull ? 0 : Convert.ToInt16(Enum.Parse(enumType, dr[col].ToString()));
        }
    }
}